import 'package:flutter/material.dart';
import 'package:merchants/screens/dashboard/default_screen.dart';
import 'package:merchants/screens/my/my_default_screen.dart';
import 'package:merchants/screens/orders/list_screen.dart';
import 'package:merchants/screens/spu/spu_list_page.dart';
import 'package:merchants/screens/category/list_page.dart';

class MainTabPage extends StatefulWidget {
  const MainTabPage({super.key});

  @override
  MainTabPageState createState() => MainTabPageState();
}

class MainTabPageState extends State<MainTabPage> {
  int _selectedIndex = 0;
  final List<Widget> _pages = [
    DashboardDefaultScreen(), // 工作台
    const SpuListPage(), // 商品管理
    const OrderDefaultScreen(), // 订单
    const MyDefaultScreen(), // 我的
  ];

  @override
  void initState() {
    super.initState();
    _setupPushListeners();
  }

  void _setupPushListeners() {
    // 保留原推送逻辑
  }

  void _onItemTapped(int index) {
    setState(() {
      _selectedIndex = index;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: _pages[_selectedIndex],
      bottomNavigationBar: BottomNavigationBar(
        items: const <BottomNavigationBarItem>[
          BottomNavigationBarItem(icon: Icon(Icons.dashboard), label: '工作台'),
          BottomNavigationBarItem(icon: Icon(Icons.store), label: '商品管理'),
          BottomNavigationBarItem(icon: Icon(Icons.receipt_long), label: '订单'),
          BottomNavigationBarItem(icon: Icon(Icons.person), label: '我的'),
          // 修改为“我的”
        ],
        currentIndex: _selectedIndex,
        selectedItemColor: Theme.of(context).primaryColor,
        // 使用主题色
        unselectedItemColor: Colors.grey,
        onTap: _onItemTapped,
        type: BottomNavigationBarType.fixed,
      ),
    );
  }
}
